<?php
namespace app\base\controller;


use think\admin\Controller;
use app\base\model\MemberOrder as MemberOrderMod;
use think\admin\helper\QueryHelper;

/**
 * 用户订单
 * @class Package
 * @package app\base\controller
 */
class MemberOrder extends Controller
{


    /**
     * 用户订单
     * @auth true
     * @menu true
     * @login true
     */
    public function index()
    {
        MemberOrderMod::mQuery()->layTable(function () {
            $this->title = '用户订单';
        }, function (QueryHelper $query) {
            $query->equal('status,type,create_type')->order('id desc');
        });

    }

    /**
     * 加量包套餐列表数据处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function _page_filter(array &$data)
    {
        foreach ($data as &$vo){
            $vo['username'] = $this->app->db->name('ai_user')->where(['id'=>$vo['user_id']])->value('username');
            switch ($vo['status']){
                case 0:
                    $vo['status_text'] = '取消';
                    break;
                case 1:
                    $vo['status_text'] = '未支付';
                    break;
                case 2:
                    $vo['status_text'] = '已支付';
                    break;
            }
            switch ($vo['type']){
                case 1:
                    $vo['type_text'] = '基础套餐';
                    break;
                case 2:
                    $vo['type_text'] = '加量包';
                    break;
                case 3:
                    $vo['type_text'] = '设备加量包';
                    break;
                case 4:
                    $vo['type_text'] = '音频';
                    break;
                case 5:
                    $vo['type_text'] = '视频	';
                    break;
            }
            switch ($vo['create_type']){
                case 1:
                    $vo['create_type_text'] = '微信支付';
                    break;
                case 3:
                    $vo['create_type_text'] = '支付宝支付';
                    break;
                case 2:
                    $vo['create_type_text'] = '渠道支付';
                    break;
            }
        }

    }


    /**
     * 添加加量包套餐
     * @auth true
     */
    public function add()
    {
        $this->title = '添加加量包套餐';
        MemberOrderMod::mForm('form');
    }

    /**
     * 表单数据处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function _form_filter(array &$data)
    {

    }
    /**
     * 编辑加量包套餐
     * @auth true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function edit()
    {
        $this->title = '编辑加量包套餐';
        MemberOrderMod::mForm('form');
    }


    /**
     * 删除加量包套餐
     * @auth true
     */
    public function remove()
    {
        MemberOrderMod::mDelete();
    }

    /**
     * 修改数据状态
     * @auth true
     */
    public function state()
    {
        MemberOrderMod::mSave($this->_vali([
            'status.in:0,1'  => '状态值范围异常！',
            'status.require' => '状态值不能为空！',
        ]));
    }




}
